home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / DELPHI.SWG / 0039_Preventing a Form from Resizing.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-02-21  |  3.1 KB  |  90 lines

  1.  
  2. In some cases, developers would want to create a regular window
  3. (Form) in Delphi that contains some of the characteristics of a
  4. dialog box.  For example, they do not want to allow their users
  5. to resize the form at runtime due to user interface design
  6. issues.  Other than creating the whole form as a dialog box,
  7. there is not a property or a method to handle this in a regular
  8. window in Delphi.  But due to the solid connection between Delphi
  9. and the API layer, developers can accomplish this easily.
  10.  
  11. The following example demonstrates a way of handling the Windows
  12. message "WM_GetMinMaxInfo" which allows the developer to restrict
  13. the size of windows (forms) at runtime to a specific value.  In
  14. this case, it will be used to disable the functionality of sizing
  15. the window (form) at runtime.
  16.  
  17. Consider the following unit:
  18.  
  19. unit getminmax;
  20.  
  21. interface
  22.  
  23. uses
  24.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
  25.  
  26. type
  27.   TForm1 = class(TForm)
  28.   private
  29.     { Private declarations }
  30.     procedure WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo);
  31.               message WM_GETMINMAXINFO;
  32.     procedure WMInitMenuPopup(var Msg: TWMInitMenuPopup);
  33.               message WM_INITMENUPOPUP;
  34.     procedure WMNCHitTest(var Msg: TWMNCHitTest);
  35.               message WM_NCHitTest;
  36.   public
  37.     { Public declarations }
  38.   end;
  39.  
  40. var
  41.   Form1: TForm1;
  42.  
  43. implementation
  44.  
  45. {$R *.DFM}
  46.  
  47.  procedure TForm1.WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo);
  48.  begin
  49.      inherited;
  50.      with Msg.MinMaxInfo^ do
  51.      begin
  52.           ptMinTrackSize.x:= form1.width;
  53.           ptMaxTrackSize.x:= form1.width;
  54.           ptMinTrackSize.y:= form1.height;
  55.           ptMaxTrackSize.y:= form1.height;
  56.      end;
  57.  end;
  58.  
  59.  procedure TForm1.WMInitMenuPopup(var Msg: TWMInitMenuPopup);
  60.  begin
  61.       inherited;
  62.       if Msg.SystemMenu then
  63.          EnableMenuItem(Msg.MenuPopup, SC_SIZE, MF_BYCOMMAND or MF_GRAYED)
  64.  end;
  65.  
  66.  procedure TForm1.WMNCHitTest(var Msg: TWMNCHitTest);
  67.  begin
  68.       inherited;
  69.       with Msg do
  70.            if Result in [HTLEFT, HTRIGHT, HTBOTTOM, HTBOTTOMRIGHT,
  71.                      HTBOTTOMLEFT, HTTOP, HTTOPRIGHT, HTTOPLEFT] then
  72.               Result:= HTNOWHERE
  73.  end;
  74. end.  { End of Unit}
  75.  
  76. A message handler for the windows message "WM_GetMinMaxInfo" in
  77. the code above was used to set the minimum and maximum TrackSize
  78. of the window to equal the width and height of the form at design
  79. time.  That was actually enough to disable the resizing of the
  80. window (form), but the example went on to handle another couple
  81. of messages just to make the application look professional.  The
  82. first message was the "WMInitMenuPopup"  and that was to gray out
  83. the size option from the System Menu so that the application does
  84. not give the impression that this functionality is available.
  85. The second message was the "WMNCHitTest" and that was used to
  86. disable the change of the cursor icon whenever the mouse goes
  87. over one of the borders of the window (form) for the same reason
  88. which is not to give the impression that the resizing
  89. functionality is available.
  90.